package com.itheima.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.commit.R;
import com.itheima.pojo.Employee;
import com.itheima.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/employee")
@Slf4j
public class EmployeeController {

    @Autowired
    private EmployeeService employeeService;

    @PostMapping("/login")
    public R<Employee> login(HttpServletRequest request,@RequestBody Employee employee){
        return employeeService.login(request, employee);
    }
    @PostMapping("/logout")
    public R<String> logout(HttpServletRequest request) {
        return employeeService.logout(request);
    }

    @PostMapping
    public R<String> add(HttpServletRequest request,@RequestBody Employee employee){
        return employeeService.add(request,employee);
    }

    @GetMapping("/page")
    public R<Page> select(int page,int pageSize ,String name){
        log.info("page={},pageSize={},name={}",page,pageSize,name);
        return employeeService.select(page,pageSize,name);
    }

    @PutMapping
    public R<String> update(HttpServletRequest request,@RequestBody Employee employee){
        return employeeService.update(request,employee);
    }

    @GetMapping("/{id}")
    public R<Employee> getById(@PathVariable Long id){
        return employeeService.getByIdd(id);
    }

}
